<?php
/**
 * Nadëb (Makú-Nadëb)
 * 
 * @author     Mateus Martins <mateusweb@gmail.com>
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    http://www.gnu.org/licenses/gpl.html | GPL
 * @package    Nadeb
 * @version    1.0.0
 */


/**
 * Class Nadeb_Report_Table
 * 
 * 
 * @category   Nadeb
 * @package    Nadeb_Report_Table
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    http://www.gnu.org/licenses/gpl.html | GPL
 */
class Nadeb_Report_Table extends Nadeb_Report_Sql
{
	/**
	 * @deprecated 2010-07-07
	 * @var array
	 */
	protected $prop;
	
	/**
	 * @var string
	 */
	protected $gd;
	
	/**
	 * Metodo Construtor da classe
	 * @param array $_params
	 */
	public function __construct($_params)
	{
		parent::__construct($_params);

		if( $this->get_totalPages() )
		{
			$this->get_data();
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * @deprecated 2010-07-07
	 *
	public function __set($_obj,$_param)
	{
		$this->prop[$_obj] = $_param;
	}
	 */
	
	/**
	 * Monta a tabela que forma o data grid
	 */
	public function create_table()
	{
		$this->get_variables();
		
		$url_path = "/{$this->params['module']}/{$this->params['controller']}/delete/";
		if( isset($this->params['rel']) )
		{
			$url_path .= "rel/" . $this->params['rel'] . "/";
		}

		if( $this->filters )
		{
			$js = Nadeb_JScontroller::get_instance();
			$js->JSInstance = "admin_filters";
			
			$url_filter = "/{$this->params['module']}/{$this->params['controller']}/";
			$sqlFilters = new Zend_Session_Namespace();
			
			$this->gd .= "<!-- FILTERS! -->\n\t<form id=\"fGridFilters\" method=\"post\" action=\"{$url_filter}\">\n";
			$this->gd .= $sqlFilters->types ? "\t\t<div class=\"filtros\">\n" : "\t\t<div class=\"filtros display_none\">\n";
			$this->gd .= "\t\t<h3>Opções de Pesquisa: </h3>\n";
			foreach($this->filters as $key => $value)
			{
				$this->gd .= call_user_func( array( "Nadeb_Report_Filters_" . ucfirst( $key ), "get_xhtml" ), $this->filters[$key] );
			}
			$this->gd .= "\t\t</div>\n";
			$this->gd .= "\t</form>\n<!-- FILTERS! -->\n";
		}
		
		$this->gd .= "<!-- DATAGRID! -->\n\t<form id=\"fGrid\" method=\"post\" action=\"{$url_path}\">\n";
		$this->gd .= "\t\t<table summary=\"{$this->title}\">\n"; 
		
		if($this->title)
		{
			$this->gd .= "	\t\t<caption>{$this->title}</caption>\n";
		}

		$this->gd .= Nadeb_Report_Header::get_xhtml( $this->headerConfigs );
		$this->gd .= Nadeb_Report_Footer::get_xhtml( $this->footerConfigs );
		$this->gd .= Nadeb_Report_Body::get_xhtml  ( $this->bodyConfigs );
			
		$this->gd .= "\t\t</table>\n";
		$this->gd .= "\t</form>\n<!-- DATAGRID! -->\n";
	}
	
	/**
	 * Retorna o XHTML do data grid
	 * 
	 * @return string
	 */
	public function get()
	{
		return $this->gd;
	}
}
